/*
 ******************************
 * Object Oriented Programming in C
 *
 * Author: Laurent Deniau, Laurent.Deniau@cern.ch
 *
 * For more information, please see the paper:
 * http://home.cern.ch/ldeniau/html/oopc/oopc.html
 *
 ******************************
 */

#include <stdio.h>

/*-----------------------------*/
/*   employee implementation   */
/*-----------------------------*/

#define IMPLEMENTATION

#include <employee.h>

/*
  ---------------------
  Object implementation
  ---------------------
*/

void
constMethodOvldDecl(print, person)
{
  sendCMsg(this, person, print);
  printf("\tdept:\t%s\n", sub_cast(this,person)->m.department);
}

OBJECT_IMPLEMENTATION

  SUPERCLASS(person)

ENDOF_IMPLEMENTATION

/*
  --------------------
  Class implementation
  --------------------
*/

initClassDecl() /* required */
{
  /* initialize super class */
  initSuper(person);

  /* overload super class methods */
  overload(person.print) = methodOvldName(print, person);
}

dtorDecl() /* required */
{
  person._person(super(this,person));
  free((void*)this->m.department);
  this->m.department = NULL;
}

t_employee
classMethodDecl_(*const new)
     char const name[], char const department[] __
{
  t_employee *const this = employee.alloc();
  if (this) employee.init(this, name, department);
  return this;
}

void
methodDecl_(init)
     char const name[], char const department[] __
{
  person.init(super(this,person), name);
  this->m.department = strdup(department);
}

void
methodDecl_(copy) t_employee const*const emp __
{
  employee._employee(this);
  employee.init(this, emp->m.person.m.name, emp->m.department);
}

CLASS_IMPLEMENTATION

  methodName(new),
  methodName(init),
  methodName(copy)

ENDOF_IMPLEMENTATION
